package com.yn.pet.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yn.pet.bus.dao.DeviceSimDao;
import com.yn.pet.bus.entity.DeviceSim;
import com.yn.pet.service.DeviceSimService;
import io.jsonwebtoken.lang.Assert;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * 设备SIM卡绑定表(DeviceSim)表服务实现类
 *
 * @author makejava
 * @since 2025-07-09 12:00:47
 */
@Service("deviceSimService")
public class DeviceSimServiceImpl extends ServiceImpl<DeviceSimDao, DeviceSim> implements DeviceSimService {

    @Override
    public DeviceSim getByIccid(String iccid) {
        Assert.hasText(iccid, "ICCID号不能为空");
        return this.list(new LambdaQueryWrapper<DeviceSim>().eq(DeviceSim::getIccid, iccid)).stream().findAny().orElse(null);
    }

    @Override
    public List<DeviceSim> listByIccid(Collection<String> iccid) {
        Assert.notEmpty(iccid, "ICCID号不能为空");
        return this.list(new LambdaQueryWrapper<DeviceSim>().in(DeviceSim::getIccid, iccid));
    }

    @Override
    public DeviceSim getByDeviceId(Long deviceId) {
        Assert.notNull(deviceId, "设备ID不能为空");
        return this.list(new LambdaQueryWrapper<DeviceSim>().eq(DeviceSim::getDeviceId, deviceId)).stream().findAny().orElse(null);
    }

    @Override
    public List<DeviceSim> listByPhoneNumber(Collection<String> phoneNumbers) {
        Assert.notEmpty(phoneNumbers, "手机号不能为空");
        return this.list(new LambdaQueryWrapper<DeviceSim>().in(DeviceSim::getPhoneNumber, phoneNumbers));
    }
}

